package com.cooba.adapter;


import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cooba.R;
import com.cooba.bean.GameEvaluationBean;
import com.cooba.bean.IntegralDetailBean;
import com.cooba.utils.ACache;
import com.cooba.utils.Utils;
import com.lidroid.xutils.BitmapUtils;

import java.util.List;

public class IntegralDetailsAdapter extends BaseAdapter {
    private Context context;
    private List<IntegralDetailBean.IntegralInfo> list;

    public List<IntegralDetailBean.IntegralInfo> getList() {
        return list;
    }

    public void setList(List<IntegralDetailBean.IntegralInfo> list) {
        this.list = list;
        Log.d("wei", ""+list.size());
        this.notifyDataSetChanged();
    }

    public void addNewData(List<IntegralDetailBean.IntegralInfo> datas) {
        if (datas != null && list != null) {
            this.list.addAll(0, datas);
            this.notifyDataSetChanged();
        }
    }

    public void addMoreData(List<IntegralDetailBean.IntegralInfo> datas) {
        Log.d("wei", "" + datas.size() + "," + list.size());
        if (datas != null && list != null) {
            list.addAll(list.size(), datas);
            this.notifyDataSetChanged();
        }
    }

    public IntegralDetailsAdapter(Context context, List<IntegralDetailBean.IntegralInfo> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list.size() == 0) {
            return 0;
        }
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.integral_detail_list_item, parent, false);
            holder.integral_time = (TextView) convertView.findViewById(R.id.integral_item_time_tv);
            holder.integral_gain_from = (TextView) convertView.findViewById(R.id.integral_item_gain_from_tv);
            holder.integral_gain_num = (TextView) convertView.findViewById(R.id.integral_item_gain_num_tv);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();

        }
        holder.integral_time.setText(list.get(position).getIntegral_time().substring(0, 10));
        String gainFrom=list.get(position).getItg_gain_from();
        String temp = null;
        switch (Integer.parseInt(gainFrom)){
            case 0:
                temp="app下载";
                break;
            case 1:
                temp="签到奖励";
                break;
            case 2:
                temp="商品兑换";
                break;
            case 3:
                temp="暂无";
                break;
            default:
                break;
        }
        holder.integral_gain_from.setText(temp);
        int num=Integer.parseInt(list.get(position).getItg_gain_num());
        if (num>0) {
            holder.integral_gain_num.setText("+"+num);
            holder.integral_gain_num.setTextColor(context.getResources().getColor(R.color.red));
        }else {
            holder.integral_gain_num.setText(""+num);
            holder.integral_gain_num.setTextColor(context.getResources().getColor(R.color.steelblue));
        }
        return convertView;
    }


    class ViewHolder {
        TextView integral_time;
        TextView integral_gain_from;
        TextView integral_gain_num;


    }

}
